package com.wandian.game.Mediators
{
	import com.wandian.game.Actions;
	import com.wandian.game.GameData;
	import com.wandian.game.RequestCommand;
	import com.wandian.game.frames.LoginFrame;
	import flash.display.Sprite;

	import com.wandian.mvc.Mediator;
	import com.wandian.net.ServerProxy;
	import com.wandian.game.Context;

	//登陆观察者，对应一个登陆精灵
	public class LoginMediator extends Mediator
	{

		private var frame:LoginFrame

		public function LoginMediator(name:String, ui:LoginFrame)
		{
			super(name, ui);
			frame=ui;
			//登陆精灵里的控件动作，在观察者里面实现
			frame.btn_login.setClickHandler(doLogin);
		}

		private function doLogin():void
		{
			//触发中介者一个进入游戏事件
			this.dispatchAction(Actions.EnterGame, null);
			return;
			//设置本地共享
			GameData.ip=frame.ip.text
			GameData.port=int(frame.port.text)
			GameData.name=frame.playerName.text
			GameData.password=frame.password.text
			GameData.gameID=int(frame.gameID.text)
			GameData.tableID=int(frame.tableID.text)
			GameData.checkCode=frame.checkCode.text
			GameData.saveCache();
			Context.GameServerProxy=new ServerProxy(GameData.ip, GameData.port);
			//给服务器发送登陆命令及参数
			Context.GameServerProxy.call(RequestCommand.PlayerLoginGameServer, playerLoginGameServer, GameData.name, GameData.password, GameData.gameID, GameData.tableID, GameData.checkCode);
			//this.dispatchAction(EnterGame, {dealerID: 0, currentCountDown: 10, totalCountDown: 10, state: LiveGameState.Beting, gameCode: null});
		}

		private function playerLoginGameServer(statusCode:int, data:Object):void
		{
			trace(statusCode);
			if (statusCode == 1)
			{
				//触发中介者一个进入游戏事件
				this.dispatchAction(Actions.EnterGame, data);
			}
		}
	}
}
